#pragma once
#include "Singleton.h"
#include "DebugManager.h"

#ifdef _DEBUG
#	ifndef JA2_ASSERTS_ON
#		define JA2_ASSERTS_ON
#	endif
#else
#	ifdef JA2_ASSERTS_ON
#		undef JA2_ASSERTS_ON
#	endif
#endif

#ifndef __FUNC__
#	define __FUNC__ __FUNCTION__
#endif

#ifdef _DEBUG
	//! Extern templates
	extern template JA2_CORE_API ja2::Singleton<ja2::DebugManager> &ja2::Singleton<ja2::DebugManager>::instance();
	extern template JA2_CORE_API ja2::Singleton<ja2::DebugManager> *ja2::Singleton<ja2::DebugManager>::instance_ptr();
	extern template JA2_CORE_API ja2::Singleton<ja2::DebugManager>::Singleton(ja2::DebugManager *);

#	define JA2_GET_DEBUG_MANAGER() ja2::Singleton<ja2::DebugManager>::instance()
#	define JA2_DEBUG_MESSAGE(TopicId, Level, Message) (JA2_GET_DEBUG_MANAGER()->topic_enabled(TopicId) ? JA2_GET_DEBUG_MANAGER()->debug_message_real(TopicId, Level, Message) : ja2::null_func())
#	define JA2_FAST_DEBUG_MESSAGE(Message) JA2_GET_DEBUG_MANAGER()->debug_message(__FILE__, __LINE__, Message)
#	define JA2_REGISTER_DEBUG_TOPIC(TopicId, Message) JA2_GET_DEBUG_MANAGER()->register_debug_topic(DebugManager::RC_ADD, TopicId, Message)
#	define JA2_UNREGISTER_DEBUG_TOPIC(TopicId, Message) JA2_GET_DEBUG_MANAGER()->register_debug_topic(DebugManager::RC_REMOVE, TopicId, Message)
#	define JA2_CLEAR_ALL_DEBUG_TOPICS() JA2_GET_DEBUG_MANAGER()->clear_all_topics()
//#	define UnRegisterDebugTopic(a, b)	DbgTopicRegistration( TOPIC_UNREGISTER, (a), (b) )
//#	define ClearAllDebugTopics( )		DbgClearAllTopics( )
//#	define ErrorMsg(a)					_DebugMessage( (a), __LINE__, __FILE__)
//#	define RegisterJA2DebugTopic(a, b)		DbgTopicRegistration( TOPIC_REGISTER, (a), (b) )
//#	define RegisterDebugTopic(a, b)		((void *)0)
//#	define DebugMsg(a, b, c)				DbgMessageReal( (a), TOPIC_MESSAGE, (b), (c) )
#else
#	define JA2_DEBUG_MESSAGE(TopicId, Level, Message) null_func()
#	define JA2_FAST_DEBUG_MESSAGE(Message) null_func()
#	define JA2_REGISTER_DEBUG_TOPIC(TopicId, Message) null_func()
#	define JA2_UNREGISTER_DEBUG_TOPIC(TopicId, Message) null_func()
#endif

#ifdef JA2_ASSERTS_ON
#	define JA2_ASSERT(Cond) ((Cond) ? ja2::null_func() : JA2_GET_DEBUG_MANAGER()->assert_message(#Cond, nullptr, __LINE__, __FUNC__, __FILE__ ))
#	define JA2_ASSERT_MESAGE(Cond, Message) ((Cond) ? ja2::null_func() : JA2_GET_DEBUG_MANAGER()->assert_message(#Cond, Message, __LINE__, __FUNC__, __FILE__ ))
#else
#	define JA2_ASSERT(Cond) null_func()
#	define JA2_ASSERT_MESAGE(Cond, Message) null_func()
#endif

namespace ja2
{
	//! Empty function.
	inline void null_func() { }
} /*ja2*/
